<template>
  <div class="root-box">
    <div class="ql-editor" v-html="htmlData"></div>
    <div class="downloadFile">
      下载附件：
      <a :href="fileUrl" target="_blank">{{fileName}}</a>
    </div>
  </div>
</template>

<script>
import * as dd from "dingtalk-jsapi"; // 此方式为整体加载，也可按需进行加载
export default {
  data() {
    return {
      htmlData: "",
      fileUrl: "",
      fileName: "",
      id: "",
    };
  },
  created() {
    var self = this;
    // dd登录
    dd.ready(function () {
      dd.runtime.permission.requestAuthCode({
        corpId: self.$route.query.corpId, // 企业id
        onSuccess: function (info) {
          // 通过该免登授权码可以获取用户身份
          self.$api.ddLogin({ code: info.code }).then((res) => {
            if (res.data.isSuccess) {
              sessionStorage.setItem("token", res.data.data.token);
              sessionStorage.setItem("userData", JSON.stringify(res.data.data));
              self.getData();
            } else {
              self.$router.push("/emptyPage");
            }
          });
        },
        onFail: function (err) {
        },
      });
    });
  },
  methods: {
    getData() {
      this.$api
        .policyReview(
          { method: "post", type: "datagrid" },
          {
            jsdx: JSON.parse(sessionStorage.getItem("userData")).id,
            policyBaseId: this.$route.params.id
          }
        )
        .then((res) => {
          console.log(res);
          this.id = res.data.data[0].id;
          // 已读
          this.readed();
          this.htmlData = res.data.data[0].policyBase.content;
          // this.fileUrl = res.data.data.policyBase.uploadfile&&('/projectApi/upload/file'+res.data.data.policyBase.uploadfile.fileShortUrl)
          this.fileUrl =
            res.data.data[0].policyBase.uploadfile &&
            "https://wuc.irunway.cn/upload/file" +
              res.data.data[0].policyBase.uploadfile.fileShortUrl;
          // this.fileViewUrl = res.data.data.policyBase.uploadfile&&(' https://view.officeapps.live.com/op/view.aspx?src=https://wuc.irunway.cn/upload/file'+res.data.data.policyBase.uploadfile.fileShortUrl)
          var fileNameStr = res.data.data[0].policyBase.uploadfile.fileShortUrl
            .replace(/\\/g, "/")
            .split("/");
          this.fileName = fileNameStr[fileNameStr.length - 1];
        });
    },
    readed() {
      this.$api.policyReview(
        { method: "post", type: "save" },
        {
          policyBaseId: this.$route.params.id,
          id: this.id,
          isRead: 2,
          jsdx: JSON.parse(sessionStorage.getItem("userData")).id,
        }
      );
    },
  },
  computed: {
  },
};
</script>

<style scoped lang="less">
.title {
  text-align: center;
}
.little-title {
  display: flex;
  justify-content: space-around;
  color: #999;
  font-size: 12px;
}
p {
  text-indent: 2em;
}
.root-box {
  padding: 0 16px;
}
.ql-editor{
  padding: 12px 0;
}
.downloadFile {
  font-size: 14px;
  color: #333;
}
.downloadFile a {
  color: rgb(15, 155, 248);
}
</style>
